package com.smbms.config;

import com.smbms.pojo.Role;
import org.aspectj.lang.annotation.*;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * 类名：AopConfig
 * 作者：小涛
 * 创建时间：2021/9/6-19:53
 * 功能：
 */
@Component
@Aspect
public class AopConfig {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    @After("execution(* com.smbms.service.impl.UserServiceImpl.*User(..))")
    public void afterUser() {
        System.out.println("这是后置增强");
        //获取user:findPage:相关的key
        Set<String> keys = redisTemplate.keys("user:findPage:*");
        for (String key : keys) {
            //删除指定的key
            redisTemplate.delete(key);
        }
    }

    @After("execution(* com.smbms.service.impl.BillServiceImpl.*Bill(..))")
    public void afterBill(){
        //获取bill:findPage:相关的key
        Set<String> keys = redisTemplate.keys("bill:findPage:*");
        for (String key : keys) {
            //删除指定的key
            redisTemplate.delete(key);
        }
    }

    @Before("execution(* com.smbms.service.impl.UserServiceImpl.findPage(..))")
    public void beforeFindUser(){

    }
}
